2000W / 48V LLC Battery-Charger  V1.00
xmc1_rtc.c
Go to the documentation of this file.
1 
60 /*********************************************************************************************************************
61  * HEADER FILES
62  *********************************************************************************************************************/
63 #include <xmc_rtc.h>
64 
65 #if UC_FAMILY == XMC1
66 #include <xmc_scu.h>
67 
68 /*********************************************************************************************************************
69  * API IMPLEMENTATION
70  *********************************************************************************************************************/
71 /*
72  * Initialize the RTC peripheral
73  */
75 {
76  if (XMC_RTC_IsRunning() == false)
77  {
78  if (XMC_RTC_IsEnabled() == false)
79  {
81  }
82 
84 
86  {
87  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
88  }
89  RTC->TIM0 = config->time.raw0;
90  RTC->TIM1 = config->time.raw1;
91 
93  {
94  /* check SCU_MIRRSTS to ensure that no transfer over serial interface is pending */
95  }
96  RTC->ATIM0 = config->alarm.raw0;
97  RTC->ATIM1 = config->alarm.raw1;
98  }
99  return XMC_RTC_STATUS_OK;
100 }
101 
102 /*
103  * Ungates a clock node for RTC
104  */
105 void XMC_RTC_Enable(void)
106 {
107  XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_RTC);
108 }
109 
110 /*
111  * Gates a clock node for RTC
112  */
113 void XMC_RTC_Disable(void)
114 {
115  XMC_SCU_CLOCK_GatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_RTC);
116 }
117 
118 /*
119  * Suspends RTC function during CPU HALT mode
120  */
122 {
123  uint32_t regval;
124  regval = (RTC->CTR & (uint32_t)~RTC_CTR_SUS_Msk);
125  RTC->CTR = (regval | (uint32_t)debug_mode);
126 }
127 
128 /*
129  * Enable RTC periodic and alarm event(s)
130  */
131 void XMC_RTC_EnableEvent(const uint32_t event)
132 {
133  RTC->MSKSR |= event;
134 }
135 
136 /*
137  * Disable RTC periodic and alarm event(s)
138  */
139 void XMC_RTC_DisableEvent(const uint32_t event)
140 {
141  RTC->MSKSR &= ~event;
142 }
143 
144 /*
145  * Clear RTC periodic and alarm event(s)
146  */
147 void XMC_RTC_ClearEvent(const uint32_t event)
148 {
149  RTC->CLRSR = event;
150 }
151 
152 /*
153  * Checks RTC peripheral is enabled for programming to its registers
154  */
156 {
157  return !XMC_SCU_CLOCK_IsPeripheralClockGated(XMC_SCU_PERIPHERAL_CLOCK_RTC);
158 }
159 
160 #endif /* UC_FAMILY == XMC1 */
void XMC_RTC_ClearEvent(const uint32_t event)
Definition: xmc1_rtc.c:147
bool XMC_RTC_IsEnabled(void)
Definition: xmc1_rtc.c:155
XMC_RTC_STATUS_t XMC_RTC_Init(const XMC_RTC_CONFIG_t *const config)
RTC driver for XMC microcontroller family.
Definition: xmc1_rtc.c:74
void XMC_RTC_SetPrescaler(uint16_t prescaler)
Definition: xmc_rtc.c:117
#define RTC
Definition: XMC1400.h:8818
uint32_t raw1
Definition: xmc_rtc.h:195
uint32_t raw0
Definition: xmc_rtc.h:179
#define SCU_GENERAL_MIRRSTS_RTC_TIM0_Msk
Definition: XMC1400.h:4036
void XMC_RTC_Disable(void)
Definition: xmc1_rtc.c:113
void XMC_RTC_EnableEvent(const uint32_t event)
Definition: xmc1_rtc.c:131
void XMC_SCU_CLOCK_UngatePeripheralClock(const XMC_SCU_PERIPHERAL_CLOCK_t peripheral)
Definition: xmc1_scu.c:636
uint32_t raw1
Definition: xmc_rtc.h:235
bool XMC_SCU_CLOCK_IsPeripheralClockGated(const XMC_SCU_PERIPHERAL_CLOCK_t peripheral)
Definition: xmc1_scu.c:648
#define SCU_GENERAL_MIRRSTS_RTC_TIM1_Msk
Definition: XMC1400.h:4038
enum XMC_RTC_DEBUG_MODE XMC_RTC_DEBUG_MODE_t
void XMC_RTC_SetDebugMode(const XMC_RTC_DEBUG_MODE_t debug_mode)
Definition: xmc1_rtc.c:121
void XMC_RTC_DisableEvent(const uint32_t event)
Definition: xmc1_rtc.c:139
void XMC_RTC_Enable(void)
Definition: xmc1_rtc.c:105
#define RTC_CTR_SUS_Msk
Definition: XMC1400.h:2050
#define SCU_GENERAL_MIRRSTS_RTC_ATIM0_Msk
Definition: XMC1400.h:4032
XMC_RTC_ALARM_t alarm
Definition: xmc_rtc.h:263
void XMC_SCU_CLOCK_GatePeripheralClock(const XMC_SCU_PERIPHERAL_CLOCK_t peripheral)
Definition: xmc1_scu.c:628
uint32_t raw0
Definition: xmc_rtc.h:219
__STATIC_INLINE bool XMC_RTC_IsRunning(void)
Definition: xmc_rtc.h:666
enum XMC_RTC_STATUS XMC_RTC_STATUS_t
XMC_RTC_TIME_t time
Definition: xmc_rtc.h:262
#define SCU_GENERAL_MIRRSTS_RTC_ATIM1_Msk
Definition: XMC1400.h:4034
__STATIC_INLINE uint32_t XMC_SCU_GetMirrorStatus(void)
Definition: xmc_scu.h:543
uint16_t prescaler
Definition: xmc_rtc.h:264